package com.neusoft.weixin.web.account;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neusoft.weixin.service.account.MessageService;

@Controller
@RequestMapping(value = "/message")
public class MessageController {
	
	@Autowired
	protected MessageService messageService;
	
	private Logger log = LoggerFactory.getLogger(MessageController.class);
	
	@RequestMapping(value = "getMessageId")
	@ResponseBody
	public String getMessageId(HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.info("获取消息id");
		String menuId= request.getParameter("menuId");
		return messageService.getMessageByMenuId(menuId);
	}
	
	
	@RequestMapping(value = "saveMessage")
	@ResponseBody
	public String saveMessage(HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.info("保存消息");
		String messageStr = request.getParameter("data");
		JSONObject message = JSONObject.fromObject(messageStr);
		messageService.saveMessage(message);
		
		
		return "success";
	}
	
}
